﻿using FishSimulation.Model;
using System.Collections.Generic;
using System.Linq;

namespace FishSimulation.Views {
    /// <summary>
    /// Interaction logic for PondDetailView.xaml
    /// </summary>
    public partial class PondDetailView : ViewBase {
        public bool Canceled { get; set; }
                
        public PondDetailView() {
            InitializeComponent();
            this.Canceled = true;            
            this.Bind();
        }

        private void btnSave_Click(object sender, System.Windows.RoutedEventArgs e) {
            this.Canceled = false;
            Repository.Instance.Save();

            //kill all actors outside of the pond
            List<Actor> list = Repository.Instance.World.Actors.Where(x => !Repository.Instance.World.Pond.InPond(new Cord(x.X, x.Y))).ToList();
            Repository.Instance.Delete(list.ToArray());
        }

        private void Bind() {
            this.dg.ItemsSource = Repository.Instance.World.Pond.Points;
        }
    }
}
